package com.shinvent.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shinvent.common.Logger;
import com.shinvent.dao.BaseDao;
import com.shinvent.dao.T_VENDORDao;

public class Vendor extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public Vendor() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		T_VENDORDao vendorDao = null;
		response.setContentType("text/xml");
	    PrintWriter out = response.getWriter();
	    
		try{
			vendorDao = new T_VENDORDao();
			vendorDao.query();
			
			out.println("<?xml version=\"1.0\"?>");
	    	out.println("<VENDORS>");
	    	
	    	while(vendorDao.gotoNext()){
	    		out.println("<VENDOR>");
	    		out.println("<VENDOR_ID>");
	    		out.println(vendorDao.getString("VENDOR_ID"));
	    		out.println("</VENDOR_ID>");
	    		out.println("<VENDOR_NAME>");
	    		out.println(vendorDao.getString("VENDOR_NAME"));
	    		out.println("</VENDOR_NAME>");
	    		out.println("</VENDOR>");
	    	}

	    	out.println("</VENDORS>");
	    	release(vendorDao);
		}catch(Exception e){
			e.printStackTrace();
			Logger.logError(e);
		}finally{
			release(vendorDao);
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	private void release(BaseDao dao){
		try{
			dao.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
